import random
from datetime import datetime

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.103.43',
    'username': 'admin',
    'password': '@Abcd1234',
    'database': 'saas'
}
client = clickhouse_connect.get_client(**connect_info)
column_list = ['log_id', 'log_time', 'session_id', 'resource_name', 'resource_code', 'slave_account_name',
               'master_account_name', 'op_time', 'op_result', 'client_ip', 'server_ip', 'port', 'op_type_code',
               'op_type_name', 'op_content', 'master_org_name', 'user_name',
               'authorized', 'master_org_code', 'slave_org_name', 'slave_org_code', 'master_account_type',
               'slave_account_type', 'master_state', 'slave_state', 'log_type']
table_name = 'std_app_system_oper_local'
insert_data = []
for i in range(100000):
    log_id = str(random.randint(10 ** 17, 10 ** 19))
    str_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    log_time = datetime.strptime(str_time, '%Y-%m-%d %H:%M:%S')
    session_id = log_id[5::] + 'ac'
    resource_name = 'CRM'
    resource_code = 'SHNGCRM'
    slave_account_name = 'JS429'
    master_account_name = 'mijy'
    op_time = datetime.strptime('2025-02-01 13:00:00', '%Y-%m-%d %H:%M:%S')
    op_result = '0'
    client_ip = '.'.join(
        [str(random.randint(1, 255)), str(random.randint(0, 255)), str(random.randint(0, 255)),
         str(random.randint(1, 255))])
    server_ip = '192.168.2.109'
    port = '8001'
    op_type_code = '99'
    op_type_name = '批量任务管理'
    op_content = '00'
    master_org_name = '行业销售服务室'
    user_name = '陈一舟'
    authorized = '0'
    master_org_code = '203'
    slave_org_name = 'test'
    slave_org_code = '193'
    master_account_type = '00'
    slave_account_type = '1'
    master_state = '正常'
    slave_state = master_state
    log_type = 'LT_SSOLOGIN'
    insert_data.append(
        [log_id, log_time, session_id, resource_name, resource_code, slave_account_name, master_account_name, op_time,
         op_result, client_ip, server_ip, port, op_type_code, op_type_name, op_content, master_org_name, user_name,
         authorized, master_org_code, slave_org_name, slave_org_code, master_account_type, slave_account_type,
         master_state, slave_state, log_type])
client.insert(table_name, data=insert_data, column_names=column_list)
client.close()
